#ifndef SERVERMESSAGEMANAGER_H
#define SERVERMESSAGEMANAGER_H

#include <QObject>
#include <QStringList>
#include <QList>
#include "serverconnection.h"


class ServerMessageManager : public QObject
{
    Q_OBJECT
public:
    explicit ServerMessageManager(QObject *parent = 0, int port = 7777);
    ~ServerMessageManager();
    const int getPort();
    const QString getIP();

signals:
    //signals to ServerManager about connection error
    void signalConnectionError();

    //signals to ServerManager about receiving commands from client or player
    void signalSEND_NICK(int localId, QString nickname);
    void signalDISCONNECT(int playerId);
    void signalFIRE(int playerId);
    void signalMOVE(int playerId);
    void signalTURN(int playerId, char turnDirection);
    void signalSTOP_MOVE(int playerId);
    void signalSTOP_FIRE(int playerId);
    void signalUNKNOWN_COMMAND(QString str);

    //signals if player or client disconnects
    void signalPlayerDisconnected(int playerId);
    void signalClientDisconnected(int localId);

public slots:
    //slot for catching ServerConnection::signalConnectionError()
    void slotConnectionError();
    //slot for catching ServerConnection::signalReceivedFromClient(,)
    void slotReceivedFromClient(int localId, QString str);
    //slot for catching ServerConnection::signalReceivedFromPlayer(,)
    void slotReceivedFromPlayer(int playerId, QString str);
    //slots for catching signals from ServerConnection
    //  about Client or Player Disconnect
    void slotClientDisconnected(int localId);
    void slotPlayerDisconnected(int playerId);


    //slots for catching signals from ServerManager
    //  about commands (agreed to protocol) to send to Client/Clients/Player
    void slotSC_CONN_ACCEPTED(int localId, int playerId);
    void slotSC_CONN_REJECTED(int localId, QString message);

    void slotSC_PLAYERLIST(QString str);
    void slotSC_PLAYERLIST(int localId, QString str);
    void slotSC_GAME_START();
    void slotSC_GAME_END(int playerId);
    void slotSC_SEND_SNAPSHOT(QString snapshot);
    void slotSC_SEND_MAP(int width, int height, const QString& map, int health,
                         int motion_speed, int bullet_speed, int fire_rate);
    void slotSC_MOVE(int playerId);
    void slotSC_FIRE(int playerId);
    void slotSC_TURN(int playerId, char direction);
    void slotSC_STOP_MOVE(int playerId);
    void slotSC_STOP_FIRE(int playerId);

private:
    //function that parses QString and emits
    //  signal suitable to received QString for Player
    void parseToPlayersCommand(int playerId, QString str);
    //function that parses QString and emits
    //  signal suitable to received QString for Client
    void parseToClientsCommand(int localId, QString str);
    ServerConnection *serverConnection;
    int port;
};

#endif // SERVERMESSAGEMANAGER_H
